<html>
<head>
<title>WIKINDX DOCUMENTATION</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/wikindx2/docs/docs.css" type="text/css" />
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h2>WIKINDX ~ Plug-in Modules</h2>
<p> This file describes how to write a basic plug-in for WIKINDX.</p>
<p>There are two types of plug-ins:</p>
<p><a href="#menu">menu plug-ins</a><br>
  <a href="#inline">inline plug-ins</a></p>
<hr>
<p><a name="menu"><strong>Menu plug-ins</strong></a></p>
<p>Menu plug-ins have one or more menu items inserted in the WIKINDX menu specified in the plug-in. These types of plug-ins are intended for the cases where the main display table of the WIKINDX is completely dedicated to the plug-in. </p>
<p>Example:
</p>
<pre>
/****************************
**** Plug-in module example ****
      **** index.php ****
*****************************/

class example_MODULE
{
// constructor
	function example_MODULE($db, $vars, $menuInit = FALSE)
	{
		if($menuInit)
		{
			$this->menus = array(	"wikindx" => 
						array("Module"		=>	"example"),
									"help" 	=>
						array("Module Help"	=>	"helpMe"),
			);<br>// $authorize:	0 -&gt; menu item displayed for all users<br>//			1 -&gt; menu item displayed for users with write access<br>//			2 -&gt; menu item displayed only for admins.<br>			$this-&gt;authorize = 1;
			return; // Need do nothing more as this is simply menu initialisation.
		}
		$this->db = $db;
		$this->vars = $vars;
// Load the template module
		include_once("core/template/TEMPLATE.php");
		$this->template = new TEMPLATE('content');
	}
	function example()
	{
		$title = "Module Example";
		$this->template->setVar('heading', $title);
		if(array_key_exists('method', $this->vars))
			$string = "The method is " . $this->vars['method'] . '.';
		else
			$string = "No method was input.";
		$this->template->setVar('body', $string);
		return $this->template->process();
	}
	function helpMe()
	{
		include_once("core/html/MISC.php");
		$title = "Module HELP";
		$this->template->setVar('heading', $title);
		$link = MISC::a("link", "this module", 
			htmlentities("index.php?action=example_example&method=helpMePlease!"));
		$string = "No help here, try $link";
		$this->template->setVar('body', $string);
		return $this->template->process();
	}
}
 </pre>
<p>The constructor parameters <em>$db</em> and <em>$vars</em> are the database object (see the <a href = "../classes/sql/sqlClass.html">SQL</a> class) and an array of all input values from the web browser form or query string. These are set to FALSE if the constructor is initialised from the MENU system in which case <em>$menuInit</em> will be TRUE.</p>
<p><em>$this-&gt;authorize</em> controls the display of the module item in the menu system according to user permissions. This was added for WIKINDX v3.2.3. </p>
<p><strong>To get your plug-ins working, a few conditions are required: </strong></p>
<ul>
  <li>All modules must go in a folder within the /modules directory.</li>
  <li>This folder must have a file called <em>index.php.</em></li>
  <li>If the folder is called 'example', both the class name and constructor in <em>index.php</em> must be called example_MODULE.</li>
  <li>The constructor must set <em>$this-&gt;menus. </em>This is a multi-dimensional array where you define which menu(s) the module should insert itself into (the choices are: "wikindx", "file", "edit", "resource", &quot;wp&quot;, "metadata", "admin" and "help"), what is the label for the submenu item and which method within our class do we first run?</li>
  <li>If <em>$this-&gt;example</em> is not set, it is assumed to be '0'. </li>
</ul>
<p align="left">So, in the above example, and if the user has write access to the WIKINDX, an item <em>Module </em>is inserted in the <em>wikindx</em> menu with the action <em>example</em> and an item <em>Module Help</em> is inserted in the <em>help</em> menu with the action <em>helpMe</em>. In your class, there must exist the methods <em>example</em>() and <em>helpMe()</em>.</p>
<p align="left">You must use the templating system that WIKINDX uses and return the template string to the calling process as shown in the above example. Furthermore, in the interests of compatibility and future WIKINDX upgrades, you should use the WIKINDX functions where possible and as explained in the rest of this documentation. </p>
<p></p>
<hr>
<p><a name = "inline"><strong>Inline plug-ins</strong></a></p>
<p>Inline plug-ins have no associated menu item. They produce content that is inserted either above or below the WIKINDX main display table on specified WIKINDX pages and are intended for content that is additional to the page being viewed. </p>
<p>Example:</p>
<pre>
/*****
* inlineExample_MODULE
*
* inline plug-in module simple example.
* 
*****/
class inlineExample_MODULE
{
// Constructor
	function inlineExample_MODULE($db, $vars)
	{
// These two are not needed here for this simple example but show how it is possible to interface with 
// the database or with user input in a plug-in module.
		$this->db = $db; // the database object.
		$this->vars = $vars; // the GET or POST querystring or form input array.
		include_once("core/html/MISC.php");
// Which page is this attached to?
// This should be the vars['action'] value as found in wikindx3/index.php.
		$this->pluginaction = 'front'; // The front page of the WIKINDX
		$this->plugintop = MISC::a("link", "click me to print at the bottom", 
			htmlentities("index.php?action=front&inlinePluginAction=inlineExample_bottomPrint"));
		$this->pluginbottom = FALSE; // print nothing at the bottom unless specified in method below.
	}
// If no method is supplied in the form input or querystring, this is the default method that is run.
// It must be the same name as the module.
// $this->plugintop or $this->pluginbottom contains the string that will be printed either above the normal 
// wikindx output table or below it.
	function bottomPrint()
	{
		$this->plugintop = FALSE; // print nothing at the top if we use this method.
		$this->pluginbottom = "I print below the standard output table";
	}
}
</pre>
<p>The constructor parameters <em>$db</em> and <em>$vars</em> are the database object (see the <a href = "../classes/sql/sqlClass.html">SQL</a> class) and an array of all input values from the web browser form or query string.</p>
<p><strong>To get your plug-ins working, a few conditions are required: </strong></p>
<ul>
  <li>All modules must go in a folder within the /modules directory.</li>
  <li>This folder must have a file called <em>index.php.</em></li>
  <li>If the folder is called 'inlineExample', both the class name and constructor in <em>index.php</em> must be called inlineExample_MODULE.</li>
  <li><em>$this-&gt;pluginaction</em> controls on which page WIKINDX displays the output of the plug-in. It must be a valid value of <em>$vars['action']</em> as found in the top level <em>index.php</em> of WIKINDX. </li>
  <li><em>$this-&gt;plugintop</em> contains a string that is to be printed above the main WIKINDX display table. </li>
  <li><em>$this-&gt;pluginbottom</em> contains a string that is to be printed below the main WIKINDX display table.</li>
  <li>In any querystring that is sent to WIKINDX, the parameter <em>inlinePluginAction</em> controls which module method is called. The value of this parameter must be &lt;moduleName&gt;_&lt;methodName&gt;. </li>
</ul>
<p align="left">So, in the above example, on displaying the front page of WIKINDX, a hyperlink is displayed above the main display table. If the user clicks on this hyperlink, the front page is displayed again but with some text printed below the main display table.</p>
<hr>
<p>
If you write a module that you think may be of interest to other WIKINDX users, please consider releasing it under the GPL at Sourceforge -- contact sirfragalot@users.sourceforge.net for details on how to do this.
</p>

<p align="right"><a href="../index.html">WIKINDX home</a> &nbsp;&nbsp;&nbsp;&nbsp;
  <a href="index.html">WIKINDX usage</a> &nbsp;&nbsp;&nbsp;&nbsp;
  <a href="../classes/index.html">WIKINDX classes</a>
</p>
</body>
</html>
